home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / digex104.zip / DIGEXT.C next >
C/C++ Source or Header  |  1991-08-15  |  12KB  |  382 lines

  1. /*
  2.     digext.c
  3.  
  4.         by
  5.             Alvin Koh
  6.             isakoh@zpcp53.att.com
  7.             27 June 1991
  8.             (with minor, approved Toad Hall Tweaks)
  9.             (and Newt Hall Tweaks (tm), too! :-) )
  10.  
  11.     For extracting digest issues from files (including the INFO-ZIP
  12.     .sma files recently posted). Files may contain more than one
  13.     digest issue. Digests issues are located using the strings defined
  14.     in the lookup table below.
  15.  
  16.     Digest issue files created have names like IZIP091.199.
  17.  
  18.     Notes:
  19.  
  20.     1.  Carriage returns (^M) are not removed from digests. For
  21.         non-MSDOS users, use flip to remove them.
  22.  
  23.     2.  If a digest issue file already exists, it is not overwritten.
  24.  
  25.     3.  Right now, digext recognizes the digests listed in the lookup
  26.         table. Add new digest info if you need to.
  27.  
  28.     4.  One added benefit of digext is that you can use it to rename
  29.         your existing digests.
  30.  
  31.     Copyright (C) 1991, Alvin Koh.  All Rights Reserved.
  32.     Permission is granted to any individual or institution to use, copy, or
  33.     redistribute this software so long as it is not sold for profit,
  34.     provided this copyright notice is retained.
  35.  
  36.     Feel free to enhance this program, but do send me a copy of
  37.     your modifications.
  38.  
  39.  
  40.     History:
  41.     ~~~~~~~~
  42.  
  43.     1.01   27 June 1991  Alvin Koh (isakoh@zpcp53.att.com)
  44.         Creation...
  45.  
  46.     1.02   28 June 1991   David Kirschbaum (kirsch@usasoc.soc.mil)
  47.         Added include files for compilation under Turbo C.
  48.  
  49.     1.03   6 July 1991   Alvin Koh (isakoh@zpcp53.att.com)
  50.         Added lookup table to support various digest types/formats.
  51.         I have only tested digext with INFO-ZIP and UNIX-WIZARDS digests
  52.         so far, as these are the 2 digests I subscribe to currently.
  53.         Please send me your bug reports, enhancements and new formats.
  54.  
  55.     1.04   10 July 1991   Alvin Koh (isakoh@zpcp53.att.com)
  56.         Changed the various *unwieldy* sscanf formats to short and
  57.         more manageable ones. Volume and Issue variable changed from
  58.         char[80] to int.
  59.  
  60.     1.04a  13 August 1991   Cave Newt (roelofs@amelia.nas.nasa.gov)
  61.         Tweaks for VMS/VAXC compilation (didn't like void main; return 
  62.         status must be zero or else interpreted strangely; added wildcard
  63.         code).  Tested a little bit on INFO-ZIP digests.
  64.  
  65. */
  66.  
  67. #include <stdio.h>
  68. #include <string.h>
  69.  
  70. #define VERSION         "1.04a"
  71. #define DATE            "13 August 1991"
  72.  
  73. #ifdef __STDC__
  74. #include <process.h>        /* exit() */
  75. #include <io.h>             /* access() */
  76. #endif
  77.  
  78. #ifdef VMS
  79. #  include <rms.h>
  80. #  include <ssdef.h>
  81. #  include <descrip.h>
  82.    typedef struct direct {
  83.        int d_wild;        /* flag for wildcard vs. non-wild */
  84.        struct FAB fab;
  85.        struct NAM nam;
  86.        char d_qualwildname[NAM$C_MAXRSS + 1];
  87.        char d_name[NAM$C_MAXRSS + 1];
  88.    } DIR;
  89.    int _vms_findfirst(char *, DIR *);
  90.    int _vms_findnext(DIR *);
  91. #endif /* VMS */
  92.  
  93. typedef struct INFO_TABLE_T INFO_TABLE;
  94. struct INFO_TABLE_T {
  95.     char *DIGEST_BEGIN;     /* start of digest */
  96.     char *DIGEST_END;       /* end of digest */
  97.     char *DIGEST_FMT;       /* format of digest name */
  98.     char *DIGEST_SCAN;      /* scanf format to extract volume/issue number */
  99. } info_table[] = {
  100.  
  101.     "INFO-ZIP Digest",                 /* tested by Alvin Koh */
  102.     "End of INFO-ZIP Digest",
  103.     "IZIP%03d.%03d",
  104.     "%*[^V] %*s %d %*c %*s %d",
  105.  
  106.     "Info-IBMPC Digest",               /* tested by Alvin Koh */
  107.     "End of Info-IBMPC Digest",
  108.     "IIBM%03d.%03d",
  109.     "%*[^V] %*s %d %*c %*s %d",
  110.  
  111.     "INFO-C Digest",
  112.     "End of Info-C Digest",
  113.     "IC%03d.%03d",
  114.     "%*[^V] %*s %d %*c %*s %d",
  115.  
  116.     "INFO-WIZARD Digest",
  117.     "End of Info-WIZARD Digest",
  118.     "IWIZ%03d.%03d",
  119.     "%*[^V] %*s %d %*c %*s %d",
  120.  
  121.     "Info-Kermit Digest",              /* tested by Alvin Koh */
  122.     "End of Info-Kermit Digest",
  123.     "IKER%03d.%03d",
  124.     "%*[^V] %*s %d %*c %*s %d",
  125.  
  126.     "UNIX-WIZARDS Digest",             /* tested by Alvin Koh */
  127.     "End of UNIX-WIZARDS Digest",
  128.     "UWIZ%03d.%03d",
  129.     "%*[^V] %*c %d %*c %d",
  130.  
  131.     "VIRUS-L Digest",                  /* tested by Alvin Koh */
  132.     "End of VIRUS-L Digest",
  133.     "VL%03d.%03d",
  134.     "VIRUS-L %*[^V] %*s %d %*c %*s %d",
  135.  
  136.     /* add new info after this line */
  137.  
  138.     /* add new info before this line */
  139.  
  140.     NULL, NULL, NULL, NULL
  141. };
  142.  
  143. #ifdef VAXC
  144. int main(int argc, char *argv[])
  145. #else /* !VAXC */
  146. void main(argc, argv)
  147. int argc;
  148. char *argv[];
  149. #endif /* ?VAXC */
  150. {
  151.     FILE *fi;               /* digest source descriptor */
  152.     FILE *fo;               /* digest file descriptor */
  153.     char s[BUFSIZ];         /* line of text from digest source */
  154.     int Volume;             /* digest volume number */
  155.     int Issue;              /* digest issue number */
  156.     char digest[80];        /* name of digest file */
  157.     int in_digest = 0;      /* 'in digest' flag */
  158.     int i;
  159.     INFO_TABLE *it;         /* ptr for searching info table */
  160.     char digest_id[80];     /* storage for digest name */
  161.     char keyword[80];       /* use for locate 'Digest' keyword */
  162. #ifdef VMS
  163.     DIR d;                  /* struct direct for VMS wildcards */
  164. #endif /* VMS */
  165.  
  166.     if (argc == 1) {
  167.         printf("digext - The Digest Extractor v%s  (%s)\n", VERSION, DATE);
  168.         printf("(C)Copyright 1991, Alvin Koh. All Rights Reserved\n\n");
  169.         printf("Usage: digext file [ file ... ]\n");
  170.         exit(0);
  171.     }
  172.  
  173.     for (i = 1; i < argc; i++) {
  174.  
  175.         /* open raw digest source */
  176. #ifdef VMS
  177.         _vms_findfirst(argv[i], &d);
  178.         while (_vms_findnext(&d) == 0) {
  179.         if ((fi = fopen(d.d_name, "r")) == NULL) {
  180. #else /* !VMS */
  181.         if ((fi = fopen(argv[i], "r")) == NULL) {
  182. #endif /* ?VMS */
  183.             printf("Can't open %s\n", argv[i]);
  184.             continue;
  185.         }
  186.  
  187. #ifdef VMS
  188.         printf("Processing %s ...\n", d.d_name);
  189. #else /* !VMS */
  190.         printf("Processing %s...\n", argv[i]);
  191. #endif /* ?VMS */
  192.  
  193.         /* look for start of digest issue */
  194.         while (fgets(s, BUFSIZ, fi) != NULL) {
  195.  
  196.             /* found it */
  197.             if (!in_digest) {
  198.  
  199.                 /* look for 'Digest' keyword */
  200.                 sscanf(s, "%s %s", digest_id, keyword);
  201.  
  202.                 if (strcmp(keyword, "Digest") != 0)
  203.                     continue;
  204.  
  205.         /* clear keyword to prevent re-loop */
  206.         keyword[0] = '\0';
  207.  
  208.                 /* look up info table */
  209.                 it = info_table;
  210.                 while (it->DIGEST_BEGIN &&
  211.                         strncmp(it->DIGEST_BEGIN, digest_id, strlen(digest_id)))
  212.                     it++;
  213.  
  214.                 if (it->DIGEST_BEGIN == NULL) {
  215.                     printf("No info available for %s Digest\n", digest_id);
  216.                     continue;
  217.                 }
  218.  
  219.                 /* scan for volume/issue number */
  220.                 sscanf(s, it->DIGEST_SCAN, &Volume, &Issue);
  221.  
  222.                 /* form name of digest issue */
  223.                 sprintf(digest, it->DIGEST_FMT, Volume, Issue);
  224.  
  225.                 /* if already exists, skip */
  226.                 if (access(digest, 00) == 0) {
  227.                     printf("\t%s already exists\n", digest);
  228.                     continue;
  229.                 }
  230.                 printf("\tExtracting %s Digest Volume %d Issue %d\n", digest_id, Volume, Issue);
  231.  
  232.                 /* create issue file */
  233.                 if ((fo = fopen(digest, "w")) == NULL) {
  234.                     printf("Can't create %s\n", digest);
  235. #ifdef VMS
  236.                     exit(0);   /* VMS interprets exit statuses annoyingly */
  237. #else /* !VMS */
  238.                     exit(1);
  239. #endif /* ?VMS */
  240.                 }
  241.  
  242.                 /* set 'in digest' flag */
  243.                 in_digest = 1;
  244.             }
  245.  
  246.             /* found end of digest */
  247.             if (in_digest && !strncmp(s, it->DIGEST_END, strlen(it->DIGEST_END))) {
  248.                 /* reset flag */
  249.                 in_digest = 0;
  250.  
  251.                 /* print ending lines */
  252.                 fprintf(fo, "%s", s);
  253.  
  254.